package likouJava;

public class 跳跃游戏II {
    public int jump(int[] nums) {
        int steps = 0;       //记录跳跃次数
        int end = 0;         //当前跳跃的最远边界
        int farthest = 0;    //下一次跳跃能达到的最远距离

        for (int i = 0; i < nums.length - 1; i++) {
            farthest = Math.max(farthest, i + nums[i]);

            if (i == end){
                steps++;
                end = farthest;  //更新下一次边界
            }
        }
        return steps;
    }

}
